package com.coolingme.general.apply;

/**
 * 环境类角色,定义客户端需要的接口，内部维护一个当前状态角色，并负责具体状态的切换
 *
 * @author wangyue
 * @date 2020-09-25 23:58
 */
public class Context {

    public static final AbstractState STATE_A = new ConcreteStateA();
    public static final AbstractState STATE_B = new ConcreteStateB();

    /**
     * 默认角色
     */
    private AbstractState currentState = STATE_A;

    {
        STATE_A.setContext(this);
        STATE_B.setContext(this);
    }

    public AbstractState getCurrentState() {
        return currentState;
    }

    public void setCurrentState(AbstractState currentState) {
        this.currentState = currentState;
        // 设置当前环境
        this.currentState.setContext(this);
    }

    public void handle() {
        this.currentState.handle();
    }

}
